package com.coursebooking.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.coursebooking.model.Student;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Optional;

@Mapper
public interface StudentRepository extends BaseMapper<Student> {
    
    @Select("SELECT * FROM student WHERE student_id = #{studentId}")
    Student selectByStudentId(String studentId);
    
    @Select("SELECT * FROM student WHERE email = #{email}")
    Student selectByEmail(String email);
    
    @Select("SELECT COUNT(*) FROM student WHERE student_id = #{studentId}")
    int countByStudentId(String studentId);
    
    @Select("SELECT COUNT(*) FROM student WHERE email = #{email}")
    int countByEmail(String email);
    
    // 为了保持兼容性，添加包装方法
    default Optional<Student> findByStudentId(String studentId) {
        return Optional.ofNullable(selectByStudentId(studentId));
    }
    
    default Optional<Student> findByEmail(String email) {
        return Optional.ofNullable(selectByEmail(email));
    }
    
    default boolean existsByStudentId(String studentId) {
        return countByStudentId(studentId) > 0;
    }
    
    default boolean existsByEmail(String email) {
        return countByEmail(email) > 0;
    }
}